#! /bin/sh
#作者:囫碾
cd /sys/class/leds/ || exit #进入工作目录
until

    echo "1.控制绿色LED"
    echo "2.控制红色LED"
    echo "3.控制蓝色LED"
    echo "4.保存"
    echo "5.开机自动应用"
    echo "6.查看保存的配置文件"
    echo "7.退出"
    read -p "输入选择:" input
    test "$input" = 7
do
    case $input in
    1)
        echo "当前可设置的LED行为"
        cat green:internet/trigger
        read -p "选择led行为:" green
        echo "$green" >green:internet/trigger
        ;;
    2)
        echo "当前可设置的LED行为"
        cat red:os/trigger
        read -p "选择led行为:" red
        echo "$red" >red:os/trigger
        ;;
    3)
        echo "当前可设置的LED行为"
        cat blue:wifi/trigger
        read -p "选择led行为:" blue
        echo "$blue" >blue:wifi/trigger
        ;;
    4)
        cat <<EOF >/etc/rc-led.local
#!/bin/sh -e
# LED配置脚本
sleep 3
echo $red > /sys/class/leds/red\:os/trigger
echo $blue > /sys/class/leds/blue\:wifi/trigger
echo $green > /sys/class/leds/green\:internet/trigger
exit 0
EOF
        chmod 0755 /etc/rc-led.local
        ;;
    5)
        cat <<EOF >/etc/systemd/system/rc-led-local.service
[Unit]
Description=/etc/rc-led.local
ConditionPathExists=/etc/rc-led.local

[Service]
Type=forking
ExecStart=/etc/rc-led.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
EOF
        systemctl daemon-reload && systemctl enable rc-led-local
        history -c
        ;;
    6) dialog --title "LED配置文件" --textbox /etc/rc-led.local 10 60 ;;
    esac
done
